<template>
  <div style="margin-top: 20px">
    <Row style="padding-bottom: 16px" type="flex" align="middle">
      <div>选择销售区域:</div>
      <a @click="showSelectArea" style="margin-left: 20px">选择销售区域</a>
      <div style="margin-left: 20px">{{ areaNames }}</div>
    </Row>
    <div>
      <Card
        v-for="(gongitem, i) in gong"
        :key="i"
        dis-hover
        style="margin-top: 20px"
      >
        <div>
          <Row class="cardRow" type="flex" justify="space-between">
            <supply-dialog @getName="getSupply" />
            <Col flex="true"> 运费承担方：{{ freightPayer }} </Col>
          </Row>
          <Row class="cardRow format_table_wrap">
            <div class="min-title">供货SKU：</div>
            <Table
              border
              height="350"
              :columns="supplySkuColumns"
              :data="gongitem.supplySkuList"
              @on-selection-change="selectSku($event, i)"
            />
          </Row>
          <Row class="cardRow format_table_wrap">
            <div class="min-title">供货信息维护如下：</div>
            <skus-table
              :loading="tableLoading"
              :tableHeight="400"
              :data-source="gongitem.supplySkuInfoList"
              :columns="supplySkuInfoColumns"
            />
          </Row>
          <Row type="flex" align="middle" class="cardRow">
            <div>供货价格方式：</div>
            <RadioGroup
              v-model="gongitem.supplyPriceType"
              @on-change="handleSupplyMethodChange"
            >
              <Radio label="1">统一进价</Radio>
              <Radio label="2">区域进价</Radio>
            </RadioGroup>
          </Row>
          <Row class="cardRow" type="flex" align="middle">
            <div>设置参照城市关系:</div>
            <Button
              type="primary"
              style="margin-left: 20px"
              @click="handleSetCityLink(i)"
              >设置
            </Button>
          </Row>
          <Row class="cardRow format_table_wrap">
            <div class="min-title">供货价格相关信息如下:</div>
            <skus-table
              :loading="tableLoading"
              :table-height="500"
              :data-source="gongitem.supplyPriceType == '1'? gongitem.uniteTableData : gongitem.areaTableData"
              :columns="gongitem.supplyPriceType == '1' ? uniteColumns : areaColumns"
              @handleRowChange="handleRowChange"
              @handleCancelSelect="handleCancelSelect"
            />
          </Row>
        </div>
        <!-- 已选参照城市 -->
        <Modal width="1000" v-model="gongitem.templateModal">
          <Row
            style="padding-top: 20px; padding-bottom: 16px"
            type="flex"
            align="middle"
          >
            <div>参照城市:</div>
            <Button
              type="primary"
              style="margin-left: 20px"
              :loading="setCityLoading"
              @click="showSetTempale(i)"
              >设置参照城市
            </Button>
          </Row>
          <Row class="format_table_wrap">
            <Table
              border
              height="400"
              :columns="templateColumns"
              :data="submitReferenceCityList"
            >
              <template slot-scope="{ row }" slot="supplyCity">
                <span v-if="row.isSupply == '1'">{{ row.saleCityName }}</span>
                <span v-else>{{ row.templateCityName }}</span>
              </template>
            </Table>
          </Row>
        </Modal>
        <city-table
          :Columns="setCityColumns"
          :dataSouce="setCityData"
          @handleBatch="handleBatch"
          @submitXiaoshouCity="submitXiaoshouCity"
          @defaultCity="defaultCity"
          @selectDropDownCity="tableSelectTemplateCity"
          @ChangeSetModal="ChangeSetModal"
          :groupCheckList="groupCheckList"
          :canZhaoDefault="canZhaoDefault"
          :canZhao="canZhao"
          :cdisabled="cdisabled"
          :setModal="gongitem.setModal"
          :supplyUuid="supplyUuid"
          :supplyPriceType="gongitem.supplyPriceType"
          :templateDefaultCityUuid="templateDefaultCityUuid"
          :quyuSku="quyuSku"
          ref="cityTable"
        />
      </Card>
      <sale-city-dialog
        :dialogVisible="saleCityModal"
        :saleCityList="saleCityData"
        :hasSelectCityList="setSaleData"
        @set-sale-city="setSaleCity"
        @select-area-confirm="confirmSaleCity"
      />
    </div>
  </div>
</template>

<script>
import { ApiRequest } from '@api/basePage';
import SupplyDialog from '@/components/commodity/getSupply.vue';
import SaleCityDialog from '@/components/commodity/selectSaleCityDialog';
import { mapGetters } from 'vuex';
import CityTable from '@/components/CityTable';
import SkusTable from '@/components/skusTable';
import {
  SUPPLY_SKUINFO_COLUMNS,
  AREA_COLUMNS,
  UNITE_COLUMNS,
  SET_CITY_COLUMNS,
  REFER_CITY_RELATION_COLUMNS
} from '@/constants/supplyColumns';
import { handlePriceChangeForSingleAdd, hasEmptyPriceForSingle } from '@/utils/price';
import { queryBusinessAreaListService } from '@/api/public';

export default {
  name: 'addSupplyChild',
  components: {
    SupplyDialog,
    SaleCityDialog,
    CityTable,
    SkusTable
  },
  props: {
    topinfo: {
      type: Object,
      // eslint-disable-next-line vue/require-valid-default-prop
      default: {
        isSaleMultiUnit: '2',
        isPurchaseMultiUnit: '2'
      }
    },
    productUuid: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      tableLoading: false,
      setCityLoading: false,
      submitReferenceCityList: [],
      isSaleMultiUnit: this.topinfo.isSaleMultiUnit, // 是否钢材 1-是 2-否
      saleCityModal: false,
      templateDefaultCityUuid: '',
      saleCityData: [],
      quyuSku: [],
      xiaoshoucity: [],
      areaCodes: '',
      areaNames: '',
      chooseAll: '',
      setCityData: [],
      cdisabled: false,
      groupCheckList: [],
      canZhao: [],
      canZhaoDefault: [],
      supplySkuColumns: [
        { title: 'SKU编码', key: 'skuNo' },
        { title: '规格', key: 'specDetailStr' }
      ],
      supplyUuid: '',
      gong: [
        {
          templateModal: false,
          setModal: false,
          checkAll: [],
          selectSaleCity: '',
          selectSupplyCity: '',
          supplySkuList: [], // 供货sku列表
          supplySkuInfoList: [], // 供货信息维护列表
          SupplyUnit: '', // 供货计量单位
          supplierModal: false, // 选择供应商弹窗
          supplyPriceType: '1',
          uniteTableData: [], // 统一定价列表
          areaTableData: []
        }
      ],
      setCityColumns: SET_CITY_COLUMNS,
      templateColumns: REFER_CITY_RELATION_COLUMNS,
      supplySkuInfoColumns: SUPPLY_SKUINFO_COLUMNS,
      uniteColumns: UNITE_COLUMNS,
      areaColumns: AREA_COLUMNS,
      unitNameModal: '', // 用于搜索的数据
      baseRow: {}, // 保存当前行的数据
      baseKey: '', // 保存当前行数据的key
      linkUnitData: [], // 单位数据
      nowPage: 1, // 单位列表分页页码
      pageShow: 10, // 单位列表分页条数
      totalNum: 0, // 总数
      totalPlatNum: 0,
      setModalLoading: true,
      setSaleData: [],
      // 供货城市弹框输入框
      formInline: {
        lossRatios: 1, // 批量输入成本比例
        select: '' // 参照城市
      },
      selectionList: [], // 供货城市选中的数据
      freightPayer: '', // 运费承担方
      taxRateInvoiceInfo: {
        taxRate: '',
        invoiceType: '',
        invoiceTypeName: ''
      }
    };
  },
  computed: {
    ...mapGetters('permissions/systemBtns', ['showBtn'])
  },
  created () {
    if (this.topinfo.mainCityCode) {
      this.templateDefaultCityUuid = this.topinfo.mainCityCode;
    }
  },
  watch: {
    topinfo (val) {
      this.loadSaleAreaInfo(val)
    }
  },
  methods: {
    // 更换弹框状态
    ChangeSetModal (data) {
      this.gong[0].setModal = data;
    },
    // 默认城市发生变化
    defaultCity (e) {
      this.templateDefaultCityUuid = e;
    },
    // 选择表格中的  参照城市
    tableSelectTemplateCity (data) {
      this.setCityData = data;
    },
    // 设置参照城市-提交
    submitXiaoshouCity (data) {
      const { submitReferenceCityList, templateModal, unarr = [] } = data;
      const { taxRate, invoiceType, invoiceTypeName } = this.taxRateInvoiceInfo;
      if (unarr.length != 0) {
        unarr.forEach(item => {
          item.taxRate = taxRate
          item.invoiceType = invoiceType
          item.invoiceTypeName = invoiceTypeName
        })
      }
      this.templateModal = templateModal;
      this.submitReferenceCityList = submitReferenceCityList;
      this.$set(this.gong[0], 'areaTableData', unarr);
    },
    // 批量修改的方法
    handleBatch (data) {
      const { formInline, newDataSouce } = data;
      this.formInline = formInline;
      this.setCityData = newDataSouce;
    },
    // 供货进价方式切换
    handleSupplyMethodChange () {
      this.submitReferenceCityList = [];
    },
    // 获取供应商
    getSupply (row) {
      this.submitReferenceCityList = [];
      this.gong[0].areaTableData = [];
      this.gong[0].uniteTableData = [];
      this.supplyUuid = row.supplierCode;
      this.freightPayer = row.freightPayer;
      this.taxRateInvoiceInfo = {
        taxRate: row.taxRate,
        invoiceType: row.invoiceType,
        invoiceTypeName: row.invoiceTypeName,
      }
      this.getSkuData(0);
    },

    // 获取sku信息
    getSkuData (i) {
      var that = this;
      let data = {
        productUuid: that.productUuid
      };
      ApiRequest(
        '/sysback/skuaudit/list/getAuditSkuByProduct',
        'post',
        data,
        true
      ).then(res => {
        let retData = res.retData;
        that.gong[i].supplySkuList = retData;
        that.gong[i].supplySkuInfoList = retData.map(item => {
          let obj = { ...item };
          obj.factoryCode = '';
          obj.factoryName = '';
          obj.purchasePrice = 0;
          obj.minOrderGoodsNum = 0;
          obj.warrantyStatus = '';
          obj.warrantyDay = 0;
          obj.exchangeGoodsStatus = '';
          obj.exchangeGoodsDay = 0;
          obj.exchangeGoodsCondition = '';
          obj.returnGoodsStatus = '';
          obj.returnGoodsDay = 0;
          obj.returnGoodsCondition = '';
          obj.minSaleImperfectionsNum = 0;
          obj.productPacking = '';
          obj.otherPromise = '';
          obj.minReOrExNum = 0;
          return obj;
        });
        that.gong[i].uniteTableData = retData.map(item => {
          let obj = { ...item, ...this.taxRateInvoiceInfo };
          obj.purchasePriceType = '1';
          obj.enterPriceType = '';
          obj.templateCityUuid = '';
          obj.supplyUnit = '';
          obj.supplyMainUnit = '';
          obj.zhugong = '';
          obj.fujiliang = '';
          obj.mainPurchasePrice = 0;
          obj.addPriceType = '';
          obj.carriageRateOrPrice = '';
          obj.packRateOrPrice = '';
          obj.processRateOrPrice = '';
          obj.rebateOrPrice = '';
          obj.mainConvertRatio = 0;
          obj.freightRatio = 0;
          obj.packRatio = 0;
          obj.processChargesRatio = 0;
          obj.rebateRatio = 0;
          obj.mainUnitCostPrice = 0;
          obj.addPriceType = that.topinfo.addPriceType;
          obj.purchasePrice = 0;
          return obj;
        });
        that.quyuSku = [];
        that.gong[i].supplySkuList.forEach(function (item, index) {
          let quyuObj = {
            skuNo: item.skuNo,
            specDetailStr: item.specDetailStr,
            addPriceType: that.topinfo.addPriceType,
            mainUnitStr: item.mainUnitStr,
            purchaseUnitStr: item.purchaseUnitStr
          };
          that.quyuSku.push(quyuObj);
        });
      });
    },

    // 展示销售城市
    showSelectArea () {
      if (this.saleCityData.length == '0') {
        let data = {};
        ApiRequest(
          '/sysback/supplyinfofromsrcm/getAllAreaFromScrm',
          'post',
          data,
          true
        ).then(res => {
          if (res.retStatus == '1') {
            this.saleCityModal = true;
            this.saleCityData = res.retData;
          }
        });
      } else {
        this.saleCityModal = true;
      }
    },

    // 勾选销售区域
    setSaleCity (params) {
      const { data, chooseType } = params;
      this.setSaleData = data;
      this.chooseAll = chooseType;
    },

    // 确认销售城市
    confirmSaleCity () {
      if (this.setSaleData.length == 0) {
        return this.$Message.warning('请选择销售区域');
      }
      let codeList = [];
      let cityNameList = [];
      this.setSaleData.forEach(function (item) {
        if (!codeList.includes(item.areaCode)) {
          codeList.push(item.areaCode)
        }
        if (!cityNameList.includes(item.areaName)) {
          cityNameList.push(item.areaName)
        }
      });
      this.areaCodes = codeList.join(',');
      this.areaNames = cityNameList.join(',');
      this.saleCityModal = false;
      this.submitReferenceCityList = [];
    },

    // 展示设置参照城市
    showSetTempale (i) {
      var that = this;
      that.setCityData = [];
      let data = {
        areaCode: this.areaCodes
      };
      this.setCityLoading = true;
      ApiRequest(
        '/sysback/supplyinfofromsrcm/getSupplyCityByAreaCodes',
        'post',
        data,
        true
      ).then(res => {
        this.setCityLoading = false;
        if (res.retStatus == '1') {
          res.retData.forEach(function (item, index) {
            item.isSupply = '';
            item.templateCity = '';
            item.templateCityUuid = '';
            item.buyPriceRatio = 1;
            item.costPriceRatio = 1;
          });
          that.gong[i].setModal = true;
          res.retData.forEach(item => {
            let obj = {
              ...item,
              _disabled: false
            };
            obj.saleCityName = item.cityName;
            obj.saleCityNo = item.cityCode;
            obj.saleProvinceName = item.provinceName;
            obj.saleProvinceNo = item.provinceCode;
            obj.productUuid = that.productUuid;
            obj.templateCitySaleAreaNo = item.areaCode;
            obj.templateCitySaleAreaName = item.areaName;
            that.setCityData.push(obj);
          });
          that.getSuppluCity();
          // 增加禁用表格的选中属性
          // that.setCityData = res.retData.map(item => ({ ...item, _disabled: false }));
          that.canZhao = res.retData.map(item => ({
            cityCode: item.cityCode,
            cityName: item.cityName,
            templateCitySaleAreaNo: item.areaCode,
            templateCitySaleAreaName: item.areaName,
            disabled: true
          }));
        }
      });
    },
    // 获取供货城市
    getSuppluCity () {
      let data = {
        supplierCode: this.supplyUuid
      };
      ApiRequest(
        '/sysback/supplyinfofromsrcm/getSupplyProvinceBySupplyNo',
        'post',
        data,
        true
      ).then(res => {
        if (res.retStatus == '1') {
          this.groupCheckList = res.retData;
          this.canZhaoDefault = res.retData.map(item => ({
            cityCode: item.cityCode,
            cityName: item.cityName
          }));
          if (this.topinfo.mainCityCode) {
            let flag = true;
            this.canZhaoDefault.forEach(item => {
              if (item.cityCode == this.topinfo.mainCityCode) {
                flag = false;
              }
            });
            if (flag) {
              this.canZhaoDefault.push({
                cityCode: this.topinfo.mainCityCode,
                cityName: this.topinfo.mainCityName
              });
            }
          }
          this.handleCheckAll(this.gong[0], 0);
        }
      });
    },

    // 点击设置
    handleSetCityLink (i) {
      if (!this.areaCodes) {
        return this.$message.warning('请选择销售区域')
      }
      if (!this.supplyUuid) {
        return this.$Message.warning('请先选择供应商');
      }
      this.gong[i].templateModal = true;
    },

    // 选择供货城市
    selectGCity (e, i) {
      let that = this;
      if (that.formInline.select && !e.includes(that.formInline.select)) {
        that.formInline.select = '';
      }
      // 参照城市下拉格式化
      that.canZhao.forEach(item => {
        item.disabled = true;
        if (e.includes(item.cityCode)) {
          item.disabled = false;
        }
      });
      let select = [];
      that.gong[i].checkAll.forEach(function (item, index) {
        that.groupCheckList.forEach(function (em, ex) {
          if (em.cityCode == item) {
            select.push(em);
          }
        });
      });

      let canZhaoDefault = [];
      that.gong[i].checkAll.forEach(item => {
        that.canZhao.forEach(otem => {
          if (item == otem.cityCode) {
            canZhaoDefault.push(otem);
          }
        });
      });
      canZhaoDefault = [...new Set(canZhaoDefault)];
      that.canZhaoDefault = canZhaoDefault;

      that.setCityData.forEach(function (item, index) {
        item._disabled = false;
        item.isSupply = '2';
        /* item.templateCitySaleAreaNo = ''
        item.templateCitySaleAreaName = '' */
        select.forEach(function (em, ex) {
          if (item.saleCityNo == em.cityCode) {
            item.isSupply = '1';
            item.templateCityName = em.cityName;
            item.templateCityUuid = em.cityCode;
            item.buyPriceRatio = 1;
            item.costPriceRatio = 1;
            // 如果相等的话就把表格禁用
            if (
              item.saleCityNo == item.templateCityUuid &&
              that.gong[i].supplyPriceType == '1'
            ) {
              item._disabled = true;
            }
          }
        });
        that.canZhao.forEach(ele => {
          if (
            item.isSupply !== '1' &&
            ele.disabled &&
            item.templateCityUuid == ele.cityCode
          ) {
            item.templateCityUuid = '';
          }
        });
      });
    },
    selectDropDownCity (e, row, index, i) {
      let sIndex = '';
      this.canZhao.forEach((item, index) => {
        if (item.cityCode == e.value) {
          sIndex = index;
        }
      });
      row.templateCityName = this.canZhao[sIndex].cityName;
      row.templateCityUuid = this.canZhao[sIndex].cityCode;
      row.templateCitySaleAreaNo = this.canZhao[sIndex].templateCitySaleAreaNo;
      row.templateCitySaleAreaName = this.canZhao[sIndex].templateCitySaleAreaName;
      this.setCityData[index] = row;
    },
    // 选择供货城市弹框状态改变时触发
    onVisibleChange (e, gongitem) {
      // 弹框关闭后清空复选框状态
      if (!e) {
        gongitem.checkAll = [];
        this.formInline.lossRatios = null;
        this.formInline.select = '';
      }
    },
    // 取消关联
    handleCancelSelect (data) {
      const { index } = data;
      if (this.gong[0].supplyPriceType == 1) {
        this.$delete(this.gong[0].uniteTableData, index);
      } else if (this.gong[0].supplyPriceType == 2) {
        this.$delete(this.gong[0].areaTableData, index);
      }
      this.$nextTick(() => {
        this.$Message.info('删除成功', 10);
      });
    },

    // 表格input发生变化
    handleRowChange (row) {
      handlePriceChangeForSingleAdd(row)
    },

    save () {
      if (!this.areaCodes) {
        return this.$Message.warning('请选择销售区域');
      }
      if (!this.supplyUuid) {
        return this.$Message.warning('请选择供应商');
      }
      if (this.submitReferenceCityList.length == 0) {
        return this.$Message.warning('请设置参照城市关系');
      }
      let submitData = [];
      if (this.gong[0].supplyPriceType == '1') {
        submitData = this.gong[0].uniteTableData
      } else {
        submitData = this.gong[0].areaTableData
      }
      const { hasEmptyVal, msg } = hasEmptyPriceForSingle(submitData)
      if (hasEmptyVal) {
        return this.$message.warning(msg);
      }
      // 供货信息维护部分
      this.save2();
    },

    save2 () {
      var that = this;
      let list = [];
      let list3 = [];
      this.gong.forEach(function (item, index) {
        let canzhaoCode = that.templateDefaultCityUuid;
        let morencanzhao = {
          defaultTemplateCityUuid: '',
          defaultTemplateCityName: ''
        };
        that.canZhaoDefault.forEach(item => {
          if (item.cityCode == canzhaoCode) {
            morencanzhao.defaultTemplateCityUuid = item.cityCode
            morencanzhao.defaultTemplateCityName = item.cityName
          }
        });
        item.supplySkuInfoList.forEach(function (otem, ondex) {
          otem.supplyUuid = that.supplyUuid;
          otem.isMainSupply = '1';
          otem.defaultTemplateCityUuid = morencanzhao.defaultTemplateCityUuid;
          otem.defaultTemplateCityName = morencanzhao.defaultTemplateCityName;
        });
        list = item.supplySkuInfoList;
        if (item.supplyPriceType == '1') {
          item.uniteTableData.forEach(function (otem, ondex) {
            otem.supplyUuid = that.supplyUuid;
            otem.productUuid = that.productUuid;
            otem.templateCityUuid = that.templateDefaultCityUuid;
            otem.isMainSupply = '1';
          });
          list3 = item.uniteTableData;
        } else {
          item.areaTableData.forEach(function (otem, ondex) {
            otem.supplyUuid = that.supplyUuid;
            otem.productUuid = that.productUuid;
            otem.templateCitySaleAreaName = otem.saleAreaName;
            otem.templateCitySaleAreaNo = otem.saleAreaUuid;
            otem.isMainSupply = '1';
          });
          list3 = item.areaTableData;
        }
      });

      let data = {
        productUuid: this.productUuid,
        areaCodes: this.areaCodes
      };
      //  入参集合所需item属性
      const listPickKeys = [
        'supplyUuid', 'productUuid', 'skuNo', 'factoryCode', 'factoryName',
        'purchasePrice', 'minOrderGoodsNum', 'warrantyStatus', 'warrantyDay',
        'exchangeGoodsStatus', 'exchangeGoodsDay', 'exchangeGoodsCondition',
        'returnGoodsStatus', 'returnGoodsDay', 'returnGoodsCondition',
        'minReOrExNum', 'minSaleImperfectionsNum', 'productPacking', 'otherPromise'
      ]
      this.$emit('updateLoadingState', true);
      ApiRequest(
        '/sysback/supplysaleareaproductrel/createRel?chooseAll=' +
          this.chooseAll,
        'post',
        data,
        true
      ).then(res => {
        if (res.retStatus == '1') {
          ApiRequest(
            '/sysback/supplyskurel/batchCreateSupplySkuRel?batchState=prepareing',
            'post',
            list.map(item => _.pick(item, listPickKeys))
          ).then(res => {
            if (res.retStatus == '1') {
              that.save3();
            } else {
              this.$emit('updateLoadingState', false);
            }
          });
        } else {
          this.$emit('updateLoadingState', false);
        }
      });
    },

    save3 () {
      var that = this;
      let list = [];
      let list3 = [];
      this.gong.forEach(function (item, index) {
        item.supplySkuInfoList.forEach(function (otem, ondex) {
          otem.supplyUuid = that.supplyUuid;
          otem.isMainSupply = '1';
        });
        list = item.supplySkuInfoList;
        if (item.supplyPriceType == '1') {
          item.uniteTableData.forEach(function (otem, ondex) {
            otem.supplyUuid = that.supplyUuid;
            otem.productUuid = that.productUuid;
            otem.templateCityUuid = that.templateDefaultCityUuid;
            otem.isMainSupply = '1';
          });
          list3 = item.uniteTableData;
        } else {
          item.areaTableData.forEach(function (otem, ondex) {
            otem.supplyUuid = that.supplyUuid;
            otem.productUuid = that.productUuid;
            otem.isMainSupply = '1';
          });
          list3 = item.areaTableData;
        }
      });
      // 参照城市设置提交
      ApiRequest(
        '/sysback/supplyarea/batchCreateSupplyArea',
        'post',
        this.submitReferenceCityList
      ).then(res => {
        if (res.retStatus === '1') {
          ApiRequest(
            '/sysback/supplyareaprice/batchCreateSupplyAreaPrice?batchState=prepareing',
            'post',
            list3
          ).then(res => {
            this.$emit('updateLoadingState', false);
            if (res.retStatus === '1') {
              this.$Message.success('保存成功');
              this.$router.push({
                name: 'commodityNotPerfection',
                query: { productUuid: this.productUuid }
              });
            }
          });
        } else {
          this.$emit('updateLoadingState', false);
        }
      });
    },
    // 供货城市全选按钮
    handleCheckAll (data, i) {
      let cityCodeList = this.groupCheckList.map(item => item.cityCode);
      data.checkAll = cityCodeList;
      this.selectGCity(cityCodeList, i);
    },
    // 加载销售区域信息
    async loadSaleAreaInfo (data) {
      if (this.setSaleData.length != 0) return
      if (this.saleCityData.length == 0) {
        const res = await queryBusinessAreaListService()
        this.saleCityData = res?.retData ?? []
      }
      const relSaleCities = this.saleCityData.filter(item => item.manageAreaUuid == data?.manageAreaId)
      this.updateSaleAreaInfo(relSaleCities.map(item => item.areaCode))
    },
    // 更新销售区域信息
    updateSaleAreaInfo (areaCodes) {
      this.areaNames = this.saleCityData
        .filter(item => areaCodes.includes(item.areaCode))
        .map(item => item.areaName)
        .join('')
      this.areaCodes = this.saleCityData
        .filter(item => areaCodes.includes(item.areaCode))
        .map(item => item.areaCode)
        .join(',')
      this.setSaleData = areaCodes
    },
  }
};
</script>

<style lang="less" scoped>
.cardRow {
  padding: 8px 0;
}

.min-title {
  font-size: 14px;
  min-height: 50px;
  line-height: 50px;
  color: #17233d;
  font-weight: bold;
}
</style>
